import { getHospitalDetails } from '../../api/pubService/pubService'
import { _t } from '.././../i18n/base'
Page({
  data: {
    authInfo: {},
    detail: {},
  },
  // 跳转地图
  toMapHandle() {
    wx.navigateTo({
      url: `/pages/interactionMap/interactionMap?location=${this.data.detail.hosName}`,
    })
  },
  // 获取医院详情
  async getHospitalDetails(e) {
    let { result } = await getHospitalDetails(e)
    if (result) {
      this.setData({
        detail: result,
      })
    }
    console.log(this.data.authInfo.tele)
  },
  // 拨打电话
  makeCallHandle(e) {
    wx.showModal({
      cancelColor: '#F95F22',
      cancelText: this.data.lang['取消'],
      confirmColor: '#999999',
      confirmText: this.data.lang['确定'],
      content: this.data.lang['前往拨打界面'],
      showCancel: true,
      success: (result) => {
        if (result.confirm) {
          wx.makePhoneCall({
            phoneNumber: this.data.authInfo.tele,
          })
        }
      },
    })
  },
  onLoad(e) {
    let lang = wx.getStorageSync('lang')
    if (e.detail) {
      this.setData({
        lang: _t(),
        authInfo: JSON.parse(e.detail),
      })
      this.getHospitalDetails({ id: this.data.authInfo.id, language: lang })
    }
  },
})
